from flask import Flask
from flask import render_template

app = Flask(__name__)


@app.route("/notes")
def notes():
    text = "Hello Flask"
    numbe = 10 / 0
    return render_template("notes.html", text=text)


@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404


@app.errorhandler(500)
def page_not_found(e):
    return render_template('500.html'), 500


@app.route("/welcome")
def welcome():
    # 用户信息
    user_name = input("请输入用户信息:")
    return render_template("user.html", user=user_name)


@app.route("/books")
def infos():
    p_list = {
        "fruit": ["猕猴桃","橙子","苹果", "葡萄","哈密瓜"],
        "books": [
            {
                "name": "西游记",
                "author": "吴承恩",
                "price": 239,
            },
            {
                "name": "红楼梦",
                "author": "曹雪芹",
                "price": 99,
            },
            {
                "name": "水浒传",
                "author": "施耐庵",
                "price": 59,
            },
            {
                "name": "狂人日记",
                "author": "鲁迅",
                "price": 69,
            }
        ]
    }
    return render_template('list.html', **p_list)


@app.route("/macros")
def show():
    return render_template("testmacro.html")

@app.route("/test")
def test():
    return render_template("test.html")


if __name__ == '__main__':
    app.run()
